<?php 
class MailComponent
{
    public static function findPasswdContent($code, $email)
    {
        $host = $_SERVER['HTTP_HOST'] ;
        $subject = '福天下密码找回';
        $content = "<!DOCTYPE html>
                <html>
                <head>
                <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>
                </head>
                <body>
                <p>你正在使用邮箱".$email."找回福天下客户端账号密码，你的验证码：".$code."</p>
                <p>请勿将此验证码提供给他人，以防信息泄漏</p>
                <p><a href='".Yii::app()->request->hostInfo."'>福天下</a></p>
                <p style='font-size:12px;'>(这是一封自动产生的email，请勿回复。)</p>
                </body>
                </html>";
        return compact('subject','content');
    }

    public static function checkMailContent($code, $email)
    {
        $host = $_SERVER['HTTP_HOST'] ;
        $subject = '福天下邮箱验证';
        $content = "<!DOCTYPE html>
                <html>
                <head>
                <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>
                </head>
                <body>
                <p>你正在使用邮箱".$email."绑定福天下客户端账号，你的验证码：".$code."</p>
                <p>请勿将此验证码提供给他人，以防信息泄漏</p>
                <p><a href='".Yii::app()->request->hostInfo."'>福天下</a></p>
                <p style='font-size:12px;'>(这是一封自动产生的email，请勿回复。)</p>
                </body>
                </html>";
        return compact('subject','content');
    }

    /**
     *  sendMail 发送邮件 
     * @param  string $address  收件地址 
     * @param  string $subject  摘要]
     * @param  string $body     邮件正文 
     * @return bool             true or false 
     */
    public static function sendMail($address,$subject = "",$body = "")
    {
        $mail = new JPhpMailer; 
        $mail->IsSMTP();
        $mail->Host = Yii::app()->params['email']['host'];//smtp.exmail.qq.com
        $mail->Post = Yii::app()->params['email']['post']; //465
        $mail->SMTPSecure  = Yii::app()->params['email']['secure'];//true
        $mail->SMTPAuth = Yii::app()->params['email']['auth'];//true
        $mail->Username   = Yii::app()->params['email']['username'];  // SMTP服务器用户名 333333@wanthings.com
        $mail->Password   = Yii::app()->params['email']['password'];            // SMTP服务器密码 ...
        $mail->SetFrom(Yii::app()->params['email']['username'], Yii::app()->name);
        $mail->Subject = $subject;
        $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
        $mail->MsgHTML($body);
        $mail->AddAddress($address, $address);
        return $mail->Send();
    }
}
?>